import {fetchBannerListAPI, fetchCatitemsListAPI, fetchFloorListAPI} from "@/api/homeApi";

const actions = {
    /* 获取轮播图的action */
    async fetchBannerList(context) {
        const {message: bannerList} = await fetchBannerListAPI()
        context.commit("updateBannerList", bannerList)
    },
    /* 获取分类选项列表的action */
    async fetchCatitemsList(context) {
        const {message: navList} = await fetchCatitemsListAPI()
        context.commit("updateCatitemsList", navList)
    },
    /* 获取楼层数据的action */
    async fetchFloorList(context) {
        const {message: floorList} = await fetchFloorListAPI()
        context.commit("updateFloorList", floorList)
    }
}
const mutations = {
    /* 更新轮播图的mutation */
    updateBannerList(state, bannerList) {
        state.bannerList = bannerList
    },
    /* 更新分类选项列表的mutation */
    updateCatitemsList(state, navList) {
        state.navList = navList
    },
    /* 更新楼层数据的mutation */
    updateFloorList(state, floorList) {
        state.floorList = floorList
    }
}
const state = () => {
    return {
        /* 轮播图的数据 */
        bannerList: [],
        /* 分类选项列表的数据 */
        navList: [],
        /* 楼层列表的数据 */
        floorList: []
    }
}
const getters = {}
export default {
    namespaced: true,
    actions,
    mutations,
    state,
    getters
}
